<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>企业密码修改</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../css/main.css" media="all">
    <link rel="stylesheet" href="../../css/enterprisePwdChange.css" media="all">
</head>
<body>

<!--主体内容-->
<div class="layui-fluid" style="padding-left: 80px;margin-top: 20px">
    <div class="layui-form" style="padding: 15px;">

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">企业ID</label>
                <div class="layui-input-inline">
                    <input placeholder="" id="enterpriseid" type="" name="priseid" lay-verify=""
                           class="layui-input imputset" style="border: 0px!important;" disabled="disabled">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">旧密码</label>
                <div class="layui-input-inline">
                    <input type="password" name="oldpwd" lay-verify="required" class="layui-input imputset">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">新密码</label>
                <div class="layui-input-inline">
                    <input type="password" name="newpwd1" lay-verify="pwd" class="layui-input imputset">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">确认新密码</label>
                <div class="layui-input-inline">
                    <input type="password" name="newpwd" lay-verify="required" class="layui-input imputset">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <div class="layui-input-inline" style="width: 300px;margin-left: 110px">
                    <div id="slider"></div>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <div class="layui-footer" style="left: 0;">
                    <button class="layui-btn" style="background-color: #ff6000" lay-submit=""
                            lay-filter="component-form-demo1">更改密码
                    </button>
                </div>
            </div>
        </div>

    </div>
</div>

<script src="../../libs/layui/layui.js"></script>
<script src="../../js/sliderVerify.js"></script>
<script type="text/javascript">
    layui.config({
        base: '../../js/'
    }).use(['layer', 'form', 'jquery', 'okUtils', 'okMd5', 'okLayer'], function () {
        var sliderVerify = layui.sliderVerify
            , $ = layui.jquery
            , layer = layui.layer
            , form = layui.form
            , okUtils = layui.okUtils
            , okLayer = layui.okLayer
            , okMd5 = layui.okMd5
            , slider = sliderVerify.render({
            elem: '#slider',
            onOk: function () {
                layer.msg("验证通过");
            }
        })

        // 获取contentText
        const ctx = function () {
            let pathName = document.location.pathname;
            let index = pathName.substr(1).indexOf("/");
            let result = pathName.substr(0, index + 1);
            return result;
        }();
        //从cookie获取企业ID
        var enterprise = JSON.parse(window.sessionStorage.getItem("enterprise"));
        $("#enterpriseid").val(enterprise.enterpriseid)
        //自建的密码规则验证
        form.verify({
            pwd: [/^[\S]{6,12}$/, "密码必须6到12位，且不能出现空格"]
        });

        //提交
        form.on('submit(component-form-demo1)', function (obj) {
            var field = obj.field;

            //确认密码
            if (field.newpwd1 !== field.newpwd) {
                return layer.msg('两次密码输入不一致', {icon: 5});
            }
            if (okMd5(field.oldpwd) !== enterprise.password) {
                return layer.msg('原密码输入不正确', {icon: 5});
            }

            if (slider.isOk()) {//用于表单验证是否已经滑动成功
            } else {
                return layer.msg("请先通过滑块验证");
            }

            field.oldpwd = okMd5(field.oldpwd);
            field.newpwd = okMd5(field.newpwd);
            layer.confirm("确定要修改密码吗？", function () {
                okUtils.ajax("/ygssecs/changepwd", "post", field, true).done(function (response) {
                    layer.open({
                        type: 0,
                        title: "修改成功",
                        icon: 1,
                        area: "300px",
                        content: "修改成功",
                        end: function () {
                            location.reload()
                        }
                    });
                }).fail(function (error) {
                    console.log(error)
                });
            })
        });

    });
</script>

</body>
</html>